#include "RenderableElement.h"
#include <regex>

using namespace misaka;

RenderableElement::RenderableElement(ITexture texture, uint8_t priority) noexcept:
_priority(priority), _texture(texture)
{
}

RenderableElement::~RenderableElement()
{
}

bool RenderableElement::operator<(const RenderableElement& elem) const noexcept
{
    return elem._priority < _priority;
}

bool RenderableElement::operator>(const RenderableElement& elem) const noexcept
{
    return elem._priority > _priority;
}

bool RenderableElement::operator==(const RenderableElement& elem) const noexcept
{
    return elem._priority == _priority;
}

bool RenderableElement::hasTag(const std::string& tag) const noexcept
{
    // TODO: using c++ regex implement this method
    std::vector<std::string> tgs;
    std::string s;

    for(auto c : _tags)
    {
        if(c == ',')
        {
            tgs.push_back(s);
            s.clear();
            continue;
        }

        s.push_back(c);
    }
    tgs.push_back(s);

    for(auto s : tgs)
    {
        if(s == tag)
        {
            return true;
        }
    }

    return false;
}

std::string RenderableElement::getTags() const noexcept
{
    return _tags;
}

void RenderableElement::appendTag(const std::string& tag) noexcept
{
    if(!_tags.empty())
    {
        _tags.push_back(',');
    }

    _tags += tag;
}

void RenderableElement::cleanTags() noexcept
{
    _tags.clear();
}

